
define(['ionic', 'utility'], function () {
    angular.module('U9Mobile.utility')
        .factory('WeChatUtil', ['$q', '$http', 'AppConstants', function ($q, $http, AppConstants) {
            var o = {};

            o.getDepartmentList = function (company, currentPage, itemsPerPage) {
                var defer = $q.defer();

                $http({
                    method: 'POST',
                    url: AppConstants.GET_DEPARTMENT_LIST_URL,
                    data: {
                        key_temp: 'abc',//faultylabs.MD5(company),
                        currentPage: currentPage,
                        itemsPerPage: itemsPerPage
                    },
                    timeout: AppConstants.HTTP_TIME_OUT
                }).success(function (data) {
                    if (data.error_code === "000000") {
                        defer.resolve(data.data);
                    } else {
                        defer.reject();
                    }
                }).error(function () {
                    defer.reject();
                });

                return defer.promise;
            };
            o.getUserList = function (company, currentPage, itemsPerPage) {
                var defer = $q.defer();

                $http({
                    method: 'POST',
                    url: AppConstants.GET_USER_LIST_URL,
                    data: {
                        key_temp: 'abc',//faultylabs.MD5(company),
                        currentPage: currentPage,
                        itemsPerPage: itemsPerPage
                    },
                    timeout: AppConstants.HTTP_TIME_OUT
                }).success(function (data) {
                    if (data.error_code === "000000") {
                        defer.resolve(data.data);
                    } else {
                        defer.reject();
                    }
                }).error(function () {
                    defer.reject();
                });

                return defer.promise;
            };

            return o;
        }]);
});